#!/bin/bash

# 快速测试修复的脚本

echo "=== LimeReader崩溃修复 - 快速测试脚本 ==="
echo ""

# 1. 检查修改文件的时间戳
echo "1. 检查源文件修改时间："
ls -lh customfilelistwidget.cpp | awk '{print $6, $7, $8, $9}'
ls -lh customfilebrowser.cpp | awk '{print $6, $7, $8, $9}'
ls -lh fileprocessworker.cpp | awk '{print $6, $7, $8, $9}'
echo ""

# 2. 检查当前运行的版本
echo "2. 检查已安装版本："
if [ -f "/Applications/LimeReader.app/Contents/MacOS/LimeReader" ]; then
    ls -lh /Applications/LimeReader.app/Contents/MacOS/LimeReader | awk '{print $6, $7, $8, $9}'
else
    echo "未安装版本不存在"
fi
echo ""

# 3. 检查build目录
echo "3. 检查build目录："
if [ -d "build" ]; then
    echo "build目录存在"
    if [ -f "build/LimeReader.app/Contents/MacOS/LimeReader" ]; then
        ls -lh build/LimeReader.app/Contents/MacOS/LimeReader | awk '{print $6, $7, $8, $9}'
    else
        echo "build中没有可执行文件"
    fi
else
    echo "build目录不存在"
fi
echo ""

# 4. 提示下一步
echo "=== 下一步操作 ==="
echo ""
echo "如果源文件比可执行文件新，需要重新编译："
echo "  ./build_macos_release.sh"
echo ""
echo "或者快速编译："
echo "  mkdir -p build && cd build"
echo "  cmake .. && make -j8"
echo ""
echo "编译完成后，部署到Applications："
echo "  cp -R build/LimeReader.app /Applications/"
echo ""
echo "从终端运行并查看日志："
echo "  /Applications/LimeReader.app/Contents/MacOS/LimeReader 2>&1 | tee ~/limereader_debug.log"
echo ""
echo "=== 检查崩溃报告 ==="
echo ""
if ls ~/Library/Logs/DiagnosticReports/LimeReader*.crash 2>/dev/null | head -1; then
    echo "找到崩溃报告，最新的："
    ls -lt ~/Library/Logs/DiagnosticReports/LimeReader*.crash 2>/dev/null | head -1
else
    echo "没有找到崩溃报告"
fi
echo ""

# 5. 检查系统日志
echo "=== 检查最近5分钟的系统日志 ==="
log show --predicate 'process == "LimeReader"' --last 5m --style compact 2>/dev/null | tail -20 || echo "无法访问系统日志"
echo ""

echo "=== 脚本完成 ==="

